package com.groupten.MyController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.groupten.Entity.StudentEntity;
import com.groupten.Service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("group10/hbjStudent") //设置访问路径
public class HbjStudentController {

    @Autowired
    private StudentService studentService;
    @RequestMapping("updateById") //表示处理什么请求
    public StudentEntity updateById(@RequestBody Map<String,String> updateData){
        Long id = Long.valueOf(updateData.get("studentId"));
        studentService.updateById(id, updateData);
        return studentService.selectById(id);
    }

    @RequestMapping("insert")  //表示处理什么请求
    public String insert(@RequestBody StudentEntity studentEntity){
        if (studentService.insert(studentEntity)){
            return "success";
        }else {
            return "fail";
        }
    }

    @RequestMapping("queryById")
    public StudentEntity query(Long id){
        return studentService.selectById(id);
    }

    @RequestMapping("queryAll")
    public IPage<StudentEntity> queryAll(Integer page, Integer limit){
        return studentService.selectAll(page, limit);
    }

    @RequestMapping("deleteById")
    public String deleteById(Long id){
        if (studentService.deleteById(id)>0){
            return "success";
        }else {
            return "fail";
        }
    }







}
